package com.project.weimi.adapter;

import java.security.PolicySpi;
import java.util.List;

import com.project.weimi.R;
import com.project.weimi.activity.OrderDetailsActivity;
import com.project.weimi.entity.response.OrderEntity;
import com.project.weimi.fragment.AllOrder_Fragment;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class AllOrder_Adapter extends BaseAdapter implements OnClickListener {
	private Context context;
	private List<OrderEntity> list;

	public AllOrder_Adapter(Context context, List<OrderEntity> list) {
		super();
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.all_order_item, null);
			holder = new ViewHolder();
			holder.trading_status_item = (TextView) convertView.findViewById(R.id.trading_status_item);
			holder.order_title_item = (TextView) convertView.findViewById(R.id.order_title_item);
			holder.order_color_item = (TextView) convertView.findViewById(R.id.order_color_item);
			holder.price_item = (TextView) convertView.findViewById(R.id.price_item);
			holder.list_item = (TextView) convertView.findViewById(R.id.list_item);
			holder.buy_num_item = (TextView) convertView.findViewById(R.id.buy_num_item);
			holder.sum_item = (TextView) convertView.findViewById(R.id.sum_item);
			holder.img_item = (ImageView) convertView.findViewById(R.id.img_item);
			holder.delete_order = (Button) convertView.findViewById(R.id.delete_order);
			holder.evaluation = (Button) convertView.findViewById(R.id.evaluation);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		//
		double sum_list = list.get(position).getBuy_num() * list.get(position).getPrice();
		double sum = ((double) (sum_list * 100.0)) / 100.0;
		holder.trading_status_item.setText(list.get(position).getTrading_status());
		holder.order_title_item.setText(list.get(position).getOrder_title());
		holder.order_color_item.setText("颜色分类：" + list.get(position).getOrder_color());
		holder.price_item.setText("¥" + list.get(position).getPrice() + "");
		holder.list_item.setText("¥" + list.get(position).getList() + "");
		holder.buy_num_item.setText("x" + list.get(position).getBuy_num() + "");
		holder.sum_item.setText("共" + list.get(position).getBuy_num() + "件商品  合计" + sum + "（含运费¥0.00）");
		holder.img_item.setImageResource(list.get(position).getImg());
		holder.delete_order.setText(list.get(position).getView_ogistics());
		holder.evaluation.setText(list.get(position).getEvaluation());

		// 按钮监听
		holder.delete_order.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				list.remove(position);
				AllOrder_Fragment.adapter.notifyDataSetChanged();
				Toast.makeText(context, "删除成功", 0).show();
			}
		});
		holder.evaluation.setOnClickListener(this);
		return convertView;
	}

	class ViewHolder {
		TextView trading_status_item, order_title_item, order_color_item, price_item, list_item, buy_num_item, sum_item;
		ImageView img_item;
		Button delete_order, evaluation;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {

		case R.id.evaluation:

			break;

		default:
			break;
		}
	}

}
